import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PartialConsumeComponent<T extends ChangeNotifier> extends StatefulWidget {
  final T model;
  final Widget? child;
  final ValueWidgetBuilder<T> builder;

  const PartialConsumeComponent(
      {super.key, required this.model, this.child, required this.builder});

  @override
  PartialConsumeComponentState<T> createState() =>
      PartialConsumeComponentState<T>();
}

class PartialConsumeComponentState<T extends ChangeNotifier>
    extends State<PartialConsumeComponent<T>> {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<T>.value(
      value: widget.model,
      child: Consumer<T>(
        builder: widget.builder,
        child: widget.child,
      ),
    );
  }
}
